//用户模块操作
const { createUser } = require("../service/user.service");
class UserController {
  async register(ctx, next) {
    // 1. 获取数据
    console.log(ctx.request.body)
    const { password,user_name} =ctx.request.body
    // 2. 操作数据库

    const res = await createUser(user_name, password)
    console.log(res)
    // 3. 返回结果
    ctx.body = {
      code: 200,
      message: res.message,
      result: 'repetition'===res.id? res.id : {
        id: res.id,
        user_name: res?.user_name,
      },
    }
  }
  async login(ctx, next) {
    //用户登录
    ctx.body = "登录成功";
  }
}

module.exports = new UserController();
